<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ page import="java.util.List" %>
<%@ page import="net.zdsoft.keel.util.DateUtils" %>
<%@ page import="net.zdsoft.keel.util.StringUtils" %>
<%@ page import="net.zdsoft.wpchat.support.client.UserAuth" %>
<%@ page import="net.zdsoft.wpchat.support.util.PageUtils" %>
<%@ page import="net.zdsoft.wpchat.support.action.auth.OperatorAction" %>
<%@ page import="net.zdsoft.wpchat.support.entity.Operator" %>
<%@ page import="net.zdsoft.wpchat.support.entity.AuthGroup" %>
<%@ page import="net.zdsoft.wpchat.support.enums.OperatorStateEnum" %>
<%
UserAuth userAuth = PageUtils.getUserAuth();
OperatorAction action = (OperatorAction) PageUtils.getAction();
List<Operator> operatorList = action.getOperatorList();
List<AuthGroup> groupList = action.getGroupList();
String groupId = action.getGroupId();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN" xml:lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>后台</title>
<style type="text/css" media="all">@import url("../../css/style.css");</style>
<script type="text/javascript" language="javascript" src="<%=request.getContextPath() %>/script/sort.js"></script>
<script language="JavaScript">
<!--
function submit(action,operatorId){
  var attention="";
  if(action=="unfreezeOperator.htm"){
    attention="您确定要对该用户进行解冻？";
  }
  else if(action=="freezeOperator.htm"){
    attention="您确定要对该用户进行冻结？";
  }
  else if(action =="removeOperator.htm"){
    attention="您确定要删除该用户吗？";
  }
  
  if (attention != ""){
    if(confirm(attention)){
      window.location.href=action+"?userId=" + operatorId;
    }
  }
}
//-->
</script>
</head>
<body>
<div id="tableMain">
  <div id="message"><%=PageUtils.errors()%><%=PageUtils.successMessage("操作成功")%></div>
  <div id="condition">
    <form name="queryForm" action="listOperator.htm" method="get">
      用户组：<select name="groupId" onchange="document.queryForm.submit()">
        <option value="">所有用户组</option><%
for (AuthGroup group: groupList){
  String selected = "";
  if (group.getId().equals(groupId)){
    selected = "selected=\"selected\"";
  }%>
        <option value="<%=group.getId()%>" <%=selected%>><%=group.getName()%></option><%
}%>         
      </select>
    </form>
  </div>
  <table id="dataTable" border="0" align="center" cellpadding="5" cellspacing="1">
  <thead>
  <tr class="titleTr">
    <td align="center">用户帐号</td>
    <td align="center">姓名</td>
    <td align="center">创建日期</td>
    <td align="center">状态</td>
    <td align="center">操作</td>
  </tr>
  </thead>
  <tbody><%
for (Operator operator: operatorList) { %>
  <tr>
    <td align="left"><%=StringUtils.htmlFilter(operator.getLoginName())%></td>
    <td align="left"><%=StringUtils.htmlFilter(operator.getName())%></td>
    <td align="center"><%=DateUtils.date2StringByDay(operator.getCreationTime())%></td>
    <td align="center"><%=OperatorStateEnum.valueOf(operator.getState())%></td>
    <td align="center" nowrap="nowrap"><%
      if (userAuth.canVisit("preModifyOperator")){%>
      <a href="preModifyOperator.htm?operatorId=<%=operator.getId()%>">修改</a><%
      }
      if (userAuth.canDo("removeOperator")){%>
      |&nbsp;<a href="javascript:submit('removeOperator.htm','<%=operator.getId()%>')">删除</a><%
      }
      if (userAuth.canDo("freezeOperator") && OperatorStateEnum.STATE_ACTIVE.equals(operator.getState())){%>
      |&nbsp;<a href="javascript:submit('freezeOperator.htm','<%=operator.getId()%>')">冻结</a><%
      }
      if (userAuth.canDo("unfreezeOperator") && OperatorStateEnum.UNUSEABLE.equals(operator.getState())){%>
      |&nbsp;<a href="javascript:submit('unfreezeOperator.htm','<%=operator.getId()%>')">解冻</a><%
      }
      if (userAuth.canVisit("preChangePassword")){%>
      |&nbsp;<a href="preChangePassword.htm?operatorId=<%=operator.getId()%>">改密码</a><%
      } %>
  </tr><%
}%>  
</tbody>
</table>
</div>
</body>
</html>
  